﻿
window.SearchKey = null;
$.MGJ.ProductType = [];
(function () {
    var _this = $.MGJ.ProductType;
    $.extend($.MGJ.ProductType, {
        GetExecl: function (ele) {
         
            $("input.AllClickChild:checked").each(function () {
                info.push($(this).attr('ID'));

            });
            if (info.length == 0) {
                $.L.msgError("请选择要导出的数据信息！");
                return
            }
            if (!$(ele).find('.no-result').hasClass('no-result')) {
  window.open(ACTION_URL("GetExecl", "Product") + "?Key=" + info);
            }
            else {
                $.L.msgWarning('导出数据不能为空！')
            }

          
        }
    });
})(jQuery);

(function () {
    var _this = $.MGJ.ProductType;
    $.extend($.MGJ.ProductType, {
    });

})(jQuery);
(function () {
 
    var _this = $.MGJ.ProductType;
    $.extend($.MGJ.ProductType, {
        ConditionModel: {
            pageIndex: 1,
            pageSize: 10,
        },
        GetProductTypeList: function (pageindex) {
            window.SearchKey = removeSpace($("#prosearch").val());
            $.L.ajaxHandle({
                url: ACTION_URL("GetProductTypeList", "Product"),
                data: {
                    prosearch: window.SearchKey,
                    pageindex: pageindex,
                    pageSize: 10
                },
                success: function (response) {
                    $("#ProductTypeData").L_bindingDataList(response);
                }
            })  
        },
        AddProductType: function (item) {
            _this.Dialog_AddTypeObj = $.L.dialog({
                url: ACTION_URL("AddType", "Product"),
                title: "新增产品类型",
                width: 700,
                height: 'auto',
                buttons: {
                    "button_save": {
                        type: 'primary',
                        text: '保存',
                        click: function () {
                            var bootstrapValidator = $("#ProductTypeD").data('bootstrapValidator');
                            bootstrapValidator.validate();
                            if (bootstrapValidator.isValid()) {
                                $(".btn-primary").attr("disabled", true);
                                $.L.ajaxHandle({
                                    url: ACTION_URL("AddProductType", "Product"),
                                    data: $("#ProductTypeD").serialize(),
                                    success: function (response) {
                                        _this.Dialog_AddTypeObj.close();
                                        $.L.msgSuccess("添加完成");
                                        _this.GetProductTypeList();
                                    }
                                })
                            }
                            else {
                                $.L.msgError("请检查数据格式！");
                            };
    
                        }
                    },
                    "button_cancel": {
                        type: 'default',
                        text: '取消',
                        click: 'MODALMISS'
                    }
                }
            });
        },
        EditProductType: function (item) {
            var _id = $(item).attr("id");
            if (!_id) {
                $.L.msgWarning("当前无法执行该操作");
                return;
            }
            _this.Dialog_EditsTypeObj = $.L.dialog({
                url: ACTION_URL("EditType", "Product")+"?id="+_id,
                title: "修改产品类型",
                width: 700,
                height: 'auto',
                buttons: {
                    "button_save": {
                        type: 'primary',
                        text: '保存',
                        click: function () {
                            var bootstrapValidator = $("#ProductTypeD").data('bootstrapValidator');
                            bootstrapValidator.validate();
                            if (bootstrapValidator.isValid()) {
                                $(".btn-primary").attr("disabled", true);
                                if ($("#Remark").val() == "") {
                                    $("#Remark").val(" ");
                                }
                                
                                $.L.ajaxHandle({
                                    url: ACTION_URL("EditProductType", "Product"),
                                    data: $("#ProductTypeD").serialize(),
                                    success: function (response) {
                                        _this.Dialog_EditsTypeObj.close();
                                        $.L.msgSuccess("更新完成");

                                        //console.log(_this.ConditionModel)

                                        _this.GetProductTypeList(_this.ConditionModel.pageIndex);
                                    }
                                })
                            }
                            else {
                                $.L.msgError("请检查数据格式！");
                            };
                        }
                    },
                    "button_cancel": {
                        type: 'default',
                        text: '取消',
                        click: 'MODALMISS'
                    }
                }
            });
        },
        //删除
        DeleteProductType: function (item) {
            $.L.msgConfirm("确认删除该数据?", function () {
                var _id = $(item).attr("id");
                if (!_id) {
                    $.L.msgWarning("当前无法执行该操作", function () {
                        _this.GetProductTypeList(_this.ConditionModel.pageIndex);
                    });
                    return;
                }
                $.L.ajaxHandle({
                    url: ACTION_URL("DeleteProductType", "Product"),
                    data: { id: _id },
                    success: function (response) {
                        $.L.msgSuccess("删除成功");
                        _this.GetProductTypeList(_this.ConditionModel.pageIndex);
                    }
                })
            })
        }

    });
})(jQuery);
(function () {
    var _this = $.MGJ.ProductType;
    $.extend($.MGJ.ProductType, {


    });
})(jQuery);
